#pragma once
// CTP2mini v1.5
#include "CTPMini1.5.8/ThostFtdcTraderApi.h"

class CTraderSpi : public CThostFtdcTraderSpi {
public:
    ///当客户端与交易后台建立起通信连接时（还未登录前）,该方法被调用。
    virtual void OnFrontConnected();

    virtual void
    OnRspAuthenticate(CThostFtdcRspAuthenticateField* pRspAuthenticateField,
                      CThostFtdcRspInfoField* pRspInfo, int nRequestID,
                      bool bIsLast);

    ///登录请求响应
    virtual void OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin,
                                CThostFtdcRspInfoField* pRspInfo,
                                int nRequestID, bool bIsLast);

    ///请求查询合约响应
    virtual void OnRspQryInstrument(CThostFtdcInstrumentField* pInstrument,
                                    CThostFtdcRspInfoField* pRspInfo,
                                    int nRequestID, bool bIsLast);

    ///错误应答
    virtual void OnRspError(CThostFtdcRspInfoField* pRspInfo, int nRequestID,
                            bool bIsLast);

    ///当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
    virtual void OnFrontDisconnected(int nReason);

private:
    void ReqAuth();
    ///用户登录请求
    void ReqUserLogin();
    ///请求查询合约
    void ReqQryInstrument();

    // 是否收到成功的响应
    bool IsErrorRspInfo(CThostFtdcRspInfoField* pRspInfo);

    void DumpToJson();

protected:
    int m_lTradingDate;
    int m_ReqCount;
};